package com.tulele.vtool.service.impl;

import com.tulele.vtool.mapper.MessageDictInfoMapper;
import com.tulele.vtool.model.MessageDictInfo;
import com.tulele.vtool.model.SysConfig;
import com.tulele.vtool.service.IMessageDictInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class MessageDictInfoServiceImpl implements IMessageDictInfoService {

    @Autowired
    private MessageDictInfoMapper messageDictInfoMapper;

//    @Value("${openMemberMenuUrl}")
//    private String openMemberMenuUrl;

    @Override
    public MessageDictInfo getInfoByKey(String dictKey) {
        return messageDictInfoMapper.getInfoByKey(dictKey);
    }

    @Override
    public String getLinkMsgByKey(String dictKey, String frontDomain,String openMemberMenuUrl) {
        MessageDictInfo messageDictInfo = messageDictInfoMapper.getInfoByKey(dictKey);
        String msg = "";
        if (messageDictInfo != null) {
            if (messageDictInfo.getDictType().equals(0)) {
                if (messageDictInfo.getLinkId().equals(7)) {//开通会员
                    msg = "<a href='" + openMemberMenuUrl + "'>" + messageDictInfo.getDictVal() + "</a>";
                } else if (messageDictInfo.getLinkId().equals(15)) {//领取优惠
                    msg = "<a href='" + openMemberMenuUrl + "&cardBag=1'>" + messageDictInfo.getDictVal() + "</a>";
                } else {
                    msg = "<a href='" + frontDomain + messageDictInfo.getLinkUrl() + "'>" + messageDictInfo.getDictVal() + "</a>";
                }
            } else if (messageDictInfo.getDictType().equals(1)) {
                msg = "<a href=\"weixin://bizmsgmenu?msgmenucontent=" + messageDictInfo.getDictText() + "&msgmenuid=+++\">" + messageDictInfo.getDictVal() + "</a>";
            }
        }
        return msg;
    }

    @Override
    public SysConfig getSysConfigByKey(String paramKey) {
        return messageDictInfoMapper.getSysConfigByKey(paramKey);
    }

    @Override
    public String getConfigValueByKey(String paramKey) {
        return messageDictInfoMapper.getConfigValueByKey(paramKey);
    }
}
